package com.helloworld.demo.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class TestHelloAQSLock {

    private static volatile int count = 0;

    //private static HelloAQSLock helloAQSLock = new HelloAQSLock();

    private static Lock lock = new ReentrantLock();

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0;i < 3;i++){
            new Thread(()->{
                lock.lock();
                try{
                    for(int j = 0; j < 10000;j++){
                        count++;
                    }
                }finally {
                    lock.unlock();
                }
            },"Thread-" + i).start();
        }

        Thread.sleep(1000);
        System.out.println(count);
    }

}
